import { reqGameDetail, reqKeySelect, reqSaleBest, reqGradeBest } from '@/api'
const state = {
    gameDetail: {},
    gameSelect: [],
    saleBestGame: [],
    gradeBestGame: []

};
const mutations = {
    GETGAMEDETAIL(state, gameDetail) {
        state.gameDetail = gameDetail;
    },
    GETGAMEBYTYPE(state, gameSelect) {
        state.gameSelect = gameSelect
    },
    GETSALEBEST(state, saleBestGame) {
        state.saleBestGame = saleBestGame
    },
    GETGRADEBEST(state, gradeBestGame) {
        state.gradeBestGame = gradeBestGame
    }
};
const actions = {
    // 点击游戏进入详情
    async getGameDetail({ commit }, gamename) {
        let res = await reqGameDetail({ gamename });
        if (res.code == 200) {
            commit('GETGAMEDETAIL', res.obj)
            return 'ok'
        } else {
            return Promise.new.Error('faile')
        }
    },
    // 类型搜索
    async getGameByType({ commit }, gametype) {
        let res = await reqKeySelect({ gametype })
        if (res.code == 200) {
            commit('GETGAMEBYTYPE', res.data)
        } else {
            return Promise.new.Error('faile')
        }
    },
    // 畅销游戏
    async getSaleBest({ commit }, code) {
        let res = await reqSaleBest({ code })
        if (res.code == 200) {
            commit('GETSALEBEST', res.data)
        } else {
            return Promise.new.Error('faile')
        }
    },
    // 评分排序游戏
    async getGradeBest({ commit }, codeInfo) {
        const { code } = codeInfo;
        let res = await reqGradeBest({ code });
        if (res.code == 200) {
            commit('GETGRADEBEST', res.data)
        } else {
            return Promise.new.Error('faile')
        }
    }
};
const getters = {};

export default {
    state,
    mutations,
    actions,
    getters
}